﻿<%
Class indexAction
	
	'''验证码
	Public Sub checkcode()
		Sa.Use("Captcha")
		Captcha.CharWidth = 18
		Captcha.CharHeight = 20
		Call Captcha.SelectTextType(2)
		Captcha.Write()
		'Set Captcha = Nothing
	End Sub
	
	'''登录页面
	Public Sub index()
		Sa.Display("")
	End Sub
	
	'''登录验证
	Public Sub login()
		Dim i_username, i_password, i_checkcode
		Sa.Dim("S_IsLogin")
		i_checkcode = P("checkcode")
		i_username = P("username")
		i_password = P("password")
		If i_username="" Then
			Sa.ErrorE("请您输入你的用户名：!")
		ElseIf i_password="" Then
			Sa.ErrorE("请您输入你的密码：")
		ElseIf i_checkcode="" Then
			Sa.ErrorE("请输入验证码：")
		ElseIf Lcase(i_checkcode)<>Lcase(Session("CheckCode")) Then
			Sa.ErrorE("alert('验证码不正确："&Session("CheckCode"))
		Else
			Sa.Use("Db")
			Db.Conn = Db.OpenConn(1,"/data/##db##/NewDataTest.mdb","")
			Dim rs : Set rs = Db.GetRecordDetail("Admin","username='"&i_username&"' And password='"&i_password&"'")
			If rs.Recordcount<>1 Then
				Sa.ErrorE("用户名、密码错误")
				S_IsLogin = False
			Else
				S_IsLogin = True
				Session("adminid") = rs("id")
				Session("admin") = rs("username")
			End If
		End If
		Db.C(rs)
		Set rs = Nothing
	End Sub
	
	'''退出
	Public Sub loginout()
		Session("adminid") = ""
	End Sub
	
	'''登录窗口
	Public Sub dialog()
		Sa.Show()
	End Sub
	
	'''Ajax登录
	Public Sub alogin()
		Dim i_username, i_password, i_checkcode
		i_checkcode = P("checkcode")
		i_username = P("username")
		i_password = P("password")
		If i_username="" Then
			Response.Write("{""statusCode"":300,""message"":""请输入您的用户名：!"",""navTabId"":"""",""rel"":"""",""callbackType"":"""",""forwardUrl"":"""",""confirmMsg"":""""}")
			Response.End()
			'Sa.ErrorE("请您输入你的用户名：!")
		ElseIf i_password="" Then
			'Sa.ErrorE("请您输入你的密码：")
			Response.Write("{""statusCode"":300,""message"":""请输入您的密码：!"",""navTabId"":"""",""rel"":"""",""callbackType"":"""",""forwardUrl"":"""",""confirmMsg"":""""}")
			Response.End()
		ElseIf i_checkcode="" Then
			'Sa.ErrorE("请输入验证码：")
			Response.Write("{""statusCode"":300,""message"":""请输入验证码：!"",""navTabId"":"""",""rel"":"""",""callbackType"":"""",""forwardUrl"":"""",""confirmMsg"":""""}")
			Response.End()
		ElseIf Lcase(i_checkcode)<>Lcase(Session("CheckCode")) Then
			'Sa.ErrorE("alert('验证码不正确："&Session("CheckCode"))
			Response.Write("{""statusCode"":300,""message"":""验证码不正确："&Session("CheckCode")&"!"",""navTabId"":"""",""rel"":"""",""callbackType"":"""",""forwardUrl"":"""",""confirmMsg"":""""}")
			Response.End()
		Else
			Sa.Use("Db")
			Db.Conn = Db.OpenConn(1,"/data/##db##/NewDataTest.mdb","")
			Dim rs : Set rs = Db.GetRecordDetail("Admin","username='"&i_username&"' And password='"&i_password&"'")
			If rs.Recordcount<>1 Then
				'Sa.ErrorE("用户名、密码错误")
				Response.Write("{""statusCode"":300,""message"":""用户名、密码错误!"",""navTabId"":"""",""rel"":"""",""callbackType"":"""",""forwardUrl"":"""",""confirmMsg"":""""}")
				Response.End()
			Else
				Session("adminid") = rs("id")
				Session("admin") = rs("username")
				Response.Write("{""statusCode"":200,""message"":""登录成功!"",""navTabId"":"""",""rel"":"""",""callbackType"":""closeCurrent"",""forwardUrl"":"""",""confirmMsg"":""""}")
			End If
		End If
		Db.C(rs)
		Set rs = Nothing
	End Sub
End Class
%>